package ru.spbau.design.snmp.android.viewer.networking;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class NetworkActivity extends Activity {

	private AlertDialog a = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		System.out.println("Hello world!");
		
		a = new android.app.AlertDialog.Builder(this).create();
		a.setMessage("          !!!          ");
		a.setButton("OK", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				System.out.println("OK pressed");
				NetworkActivity.TestNetworking();
			}
		});
	}

	public static void TestNetworking() {

		NetworkClient client = new NetworkClient();
		try {
			InputStream result = client.getXML("192.168.1.5", 1234);
			byte[] bytes=new byte[result.available()];
			result.read(bytes);
			System.out.println(new String(bytes));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void onResume() {
		super.onResume();

		System.out.println("Hello world 2!");
		a.show();
	}

}
